package com.site.wisdom_construction.config;

import com.site.wisdom_construction.util.verification.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/** @author DYF */
@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter {

  // 拦截所有请求，通过判断是否有 @LoginRequired 注解
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry
        .addInterceptor(authenticationInterceptor())
        .addPathPatterns("/**")
        .excludePathPatterns(
            ".html",
            "/swagger-resources/**",
            "/webjars/**",
            "/v2/**",
            "/swagger-ui.html/**",
            "/doc.html#/**",
            "/**");
  }

  @Bean
  public AuthenticationInterceptor authenticationInterceptor() {
    return new AuthenticationInterceptor();
  }
}
